/*
 * @lc app=leetcode.cn id=495 lang=cpp
 *
 * [495] 提莫攻击
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
        timeSeries.push_back( *(timeSeries.end()-1) + duration + 1);
        int ans = 0;
        int start = timeSeries[0];
        for(int i = 1; i < timeSeries.size(); i++)
        {
            int tmp = timeSeries[i] - start;
            ans += tmp > duration ? duration : tmp;
            start = timeSeries[i];
        }
        return ans;
    }
};
// @lc code=end

